<template>
   <!-- 首页-文章列表组件  只负责循环展示组件数据 -->
    <van-cell>
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ item.title }}</span>
          <img
            v-lazy="item.cover.images[0]"
            alt=""
            class="thumb"
            v-if="item.cover.type === 1"
          />
        </div>
        <div v-if="item.cover.type > 1" class="thumb-box">
          <img
            v-for="(urlStr, index) in item.cover.images"
            :key="index"
            v-lazy="urlStr"
            class="thumb"
            alt=""
          />
          <!-- .replace('localhost', '123.57.109.30') -->
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <span>{{
            `${item.aut_name} ${item.comm_count}评论 ${formatTime(item.pubdate)}`
          }}</span>
          <!-- 反馈按钮 -->
          <van-icon name="cross" @click.stop="btn(item.art_id)" v-if="show"/>
        </div>
      </template>
    </van-cell>
</template>

<script>
import { formatTime } from '@/utils/date.js'
export default {
  props: {
    item: Object, // 文章对象
    show: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    formatTime,
    btn (artId) {
      this.$emit('close', artId)
    }
  }
}
</script>

<style scoped lang="less">
.title-box {
  // 标题样式
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.label-box {
  // label描述样式
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.thumb {
  // 矩形黄金比例：0.618
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
